var vk = new VkApi();

var openMainPage = function (tab) {
    chrome.tabs.create({ 'url': chrome.extension.getURL("main_page.html") },
        function (tab) {
            chrome.extension.onMessage.addListener(messageListener);
        });
};

var messageListener = function (request, sender, sendResponse) {
    if (request.hash.indexOf("#access_token=") != -1) {
        console.log('Received message: ', request);
        vk.setUserId(getUserIdFromURL(request.hash));
        vk.setToken(getAccessTokenFromURL(request.hash));
        vk.setExpirationTime();
    } else {
        console.log('Received wrong message: ', request)
    }
};

chrome.browserAction.onClicked.addListener(openMainPage);
